﻿
Imports System.Data
Imports Microsoft.Data.Odbc
Imports Manejo_de_Errores

Public Class guardar

    Dim oConexion As OdbcConnection
    Public Errores As New Manejo_de_Errores.EnvioError

    Public Sub Inicializar(ByVal Cadena As String)
        oConexion = New OdbcConnection(Cadena)
        Try
            oConexion.Open()
            oConexion.Close()
        Catch ex As OdbcException
            Errores.ErrorOdbc(ex.GetBaseException)
        End Try
    End Sub


    Public Sub EnviarAGuardar(ByVal tabla As String, ByVal sCampos As String, ByVal sValores As String)
        Try
            Dim queryString As String = _
            "INSERT INTO " + tabla + " (" + sCampos + ") Values(" + sValores + ")"
            Dim command As New OdbcCommand(queryString)
            command.Connection = oConexion
            oConexion.Open()
            command.ExecuteNonQuery()
            oConexion.Close()
            MessageBox.Show("Datos guardados exitosamente.", "Operacion Exitosa", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As OdbcException
            Errores.ErrorOdbc(ex.GetBaseException)
        End Try

    End Sub
End Class
